package com.googlecode.beanfiles.translators;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Default implementation provides a list of strings. Override for more specific typing.
 */
public class PatternTranslator extends IndexedRangeTranslator {

    protected Map<String, List<Integer>> matches = new HashMap<String, List<Integer>>();

    protected static Log log() {
        return LogFactory.getLog(PatternTranslator.class);
    } 
    
    public PatternTranslator() {}

    protected void addMatch(String matchValue, List<Integer> indexes) {
        matches.put(matchValue, indexes);
        this.indexes.addAll(indexes);
    }

    public void addMatch(String matchValue, int index) {
        List<Integer> indexes = matches.get(matchValue);
        if (indexes == null) {
            indexes = new ArrayList<Integer>();
            matches.put(matchValue, indexes);
        }
        indexes.add(index);
        this.indexes.add(index);
    }

}
